package Queue_02;

/*
 * @Author 罗
 * @date 2020/3/11 - 12:30 上午
 *
 */

import org.junit.Test;

import java.util.Scanner;

public class test_01 {

    @Test
    public void test_03(){
        Queue<String> q = new Queue<>(String.class,5);
        Scanner scanner = new Scanner(System.in);
        char key;//用于接收用户输入
        boolean execute = true;
        int i= 0;
        while(execute){
            System.out.println("---->show(s) 显示队列");
            System.out.println("---->exit(e) 退出队列");
            System.out.println("---->addQueue(a)添加队列");
            System.out.println("---->getQueue(g)获取一个队列");
            System.out.println("---->headQueue(h)显示队列头数据");
            System.out.println("---->getHead(H)获取头节点，头节点获取后，会被删除");
            key = scanner.nextLine().charAt(0);

            switch (key){
                case 's' : {
                            try{
                                q.showQueue();
                            }catch(RuntimeException r){
                                System.err.println(r.getMessage());
                            }
                }break;
                case 'a' : {
                                System.out.println("请输入要加入队列的内容");
                                try{
                                    q.addQueue(scanner.nextLine());

                                }catch(RuntimeException r){
                                    System.err.println(r.getMessage());
                            }
                }break;
                case 'g' : {
                            try {
                                System.out.println(q.getQueue());

                            } catch (RuntimeException r) {
                                System.err.println(r.getMessage());
                            }
                }break;
                case 'h' :{
                            try{
                                System.out.println(q.headQueue());

                            }catch (RuntimeException r){
                                System.err.println(r.getMessage());
                            }
                }break;
                case 'H' :{
                        System.out.println(q.getHead());
                }break;
                case 'e' : {
                    execute = false;
                    scanner.close();
                } break;
            }
        }
        System.out.println("程序已经正常退出");
    }




    @Test
    public void test() throws Exception{
        Queue<String> q = new Queue<>(String.class,10);
        q.add("你好");
        for (int i = 0; i < 9; i++) {
            q.add(String.valueOf(i));
        }
        for (int i = 0; i < 9; i++) {
            System.out.println( q.subtract() );
        }
        for (int i = 1000; i < 1006; i++) {
            q.add(String.valueOf(i));
        }
        for (int i = 0; i < 9; i++) {
            System.out.println( q.subtract() );
        }
    }

    @Test
    public void test_02() throws Exception{
        Queue<String> q = new Queue<>(String.class,10);
        for (int i = 0; i < 10; i++) {
            q.addQueue(String.valueOf(i));
        }
        q.showQueue();
    }
}
